import matplotlib.pyplot as plt

# 运营能力数据
indicators = [
    'Accounts Receivable Turnover', 'Inventory Turnover', 
    'Current Asset Turnover', 'Fixed Asset Turnover', 
    'Net Asset Turnover', 'Total Asset Turnover'
]
values = [0.514, 2.359, 0.229, 0.611, 0.488, 0.119]

# 初始化累积值列表
cumulative_values = [0]
# 计算累积值
for v in values:
    cumulative_values.append(cumulative_values[-1] + v)

# 创建瀑布图
fig, ax = plt.subplots(figsize=(10, 6))

# 绘制起始点
ax.axhline(y=0, color='black', linewidth=2)

# 绘制每个指标的变化
for i in range(len(values)):
    if i == 0:
        # 第一个条形使用起始值0
        ax.barh(indicators[i], values[i], left=0, height=0.3, color='skyblue')
    else:
        # 后续条形使用前一个累积值
        ax.barh(indicators[i], values[i], left=cumulative_values[i-1], height=0.3, color='skyblue')

# 绘制结束点
ax.axhline(y=cumulative_values[-1], color='black', linewidth=2)

# 添加文本标签
for i in range(len(values)):
    if i == 0:
        ax.text(values[i], i, f'{values[i]:.3f}', va='center', ha='left', color='skyblue')
    else:
        ax.text(cumulative_values[i-1] + (values[i]/2), i, f'+{values[i]:.3f}', va='center', ha='center', color='skyblue')
    ax.text(cumulative_values[i], i, f'{cumulative_values[i]:.3f}', va='center', ha='left', color='black')

# 设置标题和标签
plt.title('Operating Capability Waterfall Chart')
plt.xlabel('Calculation Result (%)')
plt.yticks(range(len(indicators)), indicators)

# 显示图表
plt.tight_layout()
plt.show()